package com.hdaccp.user.service.impl;


import com.hdaccp.pojo.po.User;

import com.hdaccp.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private EntityManager entityManager;

    @Override
    public User login(String userId, String userpwd) {
        String jpql="from User where userId=:userId and userpwd=:userpwd and state=1 ";
          Query query=entityManager.createQuery(jpql);
        query.setParameter("userId", userId);
         query.setParameter("userpwd",userpwd);

        User user = (User) query.getSingleResult();
        return user;
         
       
    }

    @Override
    public List<User> queryPage(int currentPage, int pageSize) {
        String jpql ="select n from User n";
        Query query=entityManager.createQuery(jpql);
        query.setFirstResult((currentPage-1)*pageSize);
        query.setMaxResults(pageSize);
        return query.getResultList();
    }


}
